import { Button, Checkbox, Form, Input ,message} from 'antd';

import { useNavigate } from 'react-router-dom';
import './App.css';
import axios from 'axios';
function Login() {
    const history=useNavigate();
  const onFinish = (values) => {
    console.log('Success:', values);
    
 axios.post('https://lianghj.top:8888/api/private/v1/login',{

 password:values.password,
 username:values.username
 }).then((res)=>{
  const{data,meta}=res.data;
  if(meta.status===200){
    message.success(meta.msg)
    sessionStorage.token=data.token;
    history('/home')
  }else{
    message.error(meta.msg)
  }
  
 })

//   fetch('https://lianghj.top:8888/api/private/v1/login',{
//       method:'POST',
//       body:JSON.stringify({
//  password:values.password,
//   username:values.username
//       }),
//       headers:{
//         "Content-type": "application/json; charset=UTF-8"
//       }

//   }).then((res)=>{
//      res.json()
//   }).then((res)=>{
  
//   })

  };

  const onFinishFailed = (errorInfo) => {
    console.log('Failed:', errorInfo);
  };


  return (
    <div className="Login">
      <Form
        name="basic"
        labelCol={{
          span: 8,
        }}
        wrapperCol={{
          span: 16,
        }}
        initialValues={{
          remember: true,
        }}
        onFinish={onFinish}
        onFinishFailed={onFinishFailed}
        autoComplete="true"
      >
        <Form.Item
          label="用户名"
          name="username"
          rules={[
            {
              required: true,
              message: '请输入用户名',
            },
          ]}
        >
          <Input 
          autoComplete="true"
          />
        </Form.Item>

        <Form.Item
          label="密码"
          name="password"
          rules={[
            {
              required: true,
              message: '请输入密码',
            },
          ]}
        >
          <Input.Password autoComplete="true"/>
        </Form.Item>

        {/* <Form.Item
          name="记住密码"
          valuePropName="checked"
          wrapperCol={{
            offset: 8,
            span: 16,
          }}
        >
          <Checkbox>记住密码</Checkbox>
        </Form.Item> */}

        <Form.Item
          wrapperCol={{
            offset: 8,
            span: 16,
          }}
        >
          <Button type="primary" htmlType="登录">
           登录
          </Button>
        </Form.Item>
      </Form>
    </div>
  );
}

export default Login;
